package com.example.dangerouscargodriver.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;

import com.example.dangerouscargodriver.R;

public class ModifyPriceBottomDialog {

    private View mView;
    private EditText mPriceInput = null;

    /**
     * 定义一个接口
     */
    public interface OnItemClickListener{

        void onConfirm(String price);

        void onCancel();
    }

    /** 实例化 */
    private OnItemClickListener onItemClickListener = null;

    /**
     * 设置点击回调
     * @param on
     */
    public void setOnItemClickListener(OnItemClickListener on){
        this.onItemClickListener = on;
    }

    public void showDialog(Context context) {
        //1、使用Dialog、设置style
        final Dialog dialog = new Dialog(context, R.style.DialogTheme);
        //2、设置布局
        mView = View.inflate(context, R.layout.pop_modify_price_dialog_layout, null);
        dialog.setContentView(mView);

        mPriceInput = mView.findViewById(R.id.ed_input_price);

        Window window = dialog.getWindow();
        //设置弹出位置
        window.setGravity(Gravity.BOTTOM);
        //设置弹出动画
        window.setWindowAnimations(R.style.main_menu_animStyle);
        //设置对话框大小
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        dialog.show();

        dialog.findViewById(R.id.tv_confirm).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                if(onItemClickListener != null){
                    onItemClickListener.onConfirm(mPriceInput.getText().toString());
                }
            }
        });

        dialog.findViewById(R.id.tv_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
                if(onItemClickListener != null){
                    onItemClickListener.onCancel();
                }
            }
        });
    }
}
